<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 7/25/17
 * Time: 12:54 PM
 */

namespace frontend\modules\test\controllers;


use common\components\sms\Lhwt;
use common\components\tools\Api;
use common\components\tools\FileHelper;
use common\components\tools\ImgCompress;
use common\models\credit_app\OrderOldinfo;
use frontend\modules\test\models\Test;
use yii\web\Controller;

class TestController extends Controller
{
    public function actionTest()
    {
        $test = new Test();
        $test->on($test::EVENT_TEST, [$test, 'test1']);
        $test->test();
//        $lhwt = new Lhwt();
//        $lhwt->sendSms(['15757160474', '17858861141'], '测试短信');
    }

    public function actionTest1()
    {
        $oldinfos = OrderOldinfo::find()
            ->select(['o_app_id', 'o_gps_no', 'o_first_time'])
            ->where([
            'and',
            ['=', 'o_app_status', OrderOldinfo::O_APP_STATUS_PASS10],
            ['is', 'o_ad_money', null],
            [
                'or',
                ['and', ['like', 'o_gps_no', '391%', false], ['=', 'LENGTH(o_gps_no)', 11]],
                ['and', ['like', 'o_gps_no', '802%', false], ['=', 'LENGTH(o_gps_no)', 11]],
                ['and', ['like', 'o_gps_no', '868%', false], ['=', 'LENGTH(o_gps_no)', 15]],
            ],
        ])->asArray()->all();
        $x = [];
        foreach($oldinfos as $k => $v){
            $data = [
                'gps_serial_number'=>$v['o_gps_no'],
                'is_direct'=>1,
            ];
            if ($v['o_first_time']){
                $data['other_data'] = serialize(['o_add_time'=>strtotime($v['o_first_time'])]);
            }
            $r = Api::request('/gps/api/get-gps', $data);
            $x[] = $data;
            $x[] = $r->data['data']['other_data']['gps_status'];
        }
        return $this->render('test1', ['x'=>$x]);
    }

    public function actionTest2()
    {
//        $source = '/var/www/yii2work/frontend/runtime/tmp/15021530649509.jpg';
        $source = '/www/wwwroot/yii2work/frontend/runtime/tmp/test2.jpg';
//        $source = '/www/wwwroot/yii2work/frontend/runtime/tmp/test.png';
//        $tag = '/var/www/yii2work/frontend/runtime/tmp/2.jpg';
        $tag = '/www/wwwroot/yii2work/frontend/runtime/tmp/test2.jpg';
//        $tag = $source;
        $x = FileHelper::resizeImage($source, $tag);
        var_dump($x);exit;
    }
}